# Assign the street name for house number search
highway=* & name=* { set mkgmap:street='${name}' }
tunnel=* & tunnel:name=* & name!=$tunnel:name {name '${name} (${tunnel:name})' | '${tunnel:name} (${ref})' | '${tunnel:name}'} 
bridge=* & bridge:name=* & name!=$bridge:name  {name '${name} (${bridge:name})' |  '${bridge:name} (${ref})' | '${bridge:name}'}
include 'inc/address';
include 'inc/contours';

# clear tags
highway=proposed {delete 'highway'; delete 'oneway'; delete 'tunnel'; delete 'bridge'; delete 'ncn_from_relation'; delete 'rcn_from_relation'; delete 'icn_from_relation' delete 'lcn_from_relation'; delete 'tcn_from_relation'; delete 'mtb_from_relation'; delete 'junction' }
motor_vehicle=* { add car='${motor_vehicle}' ; delete motor_vehicle }
motorcar=*      { add car='${motorcar}' ; delete motorcar }
motorcycle=*    { delete motorcycle }
cycleway=no { delete 'cycleway' }
cycleway=track & (bicycle=no|bicycle=use_sidepath) { delete 'bicycle' }
cycleway=lane & (bicycle=no|bicycle=use_sidepath) { delete 'bicycle' }
highway=busway { set highway=service; add access=no }


(highway=motorway | highway=motorway_junction | highway=trunk | highway=footway  | route=ferry) & toll=yes {delete toll}
highway=* & toll=yes & bicycle!=no & service!=parking_aisle & toll:bicycle!=no {set toll:bicycle=yes}
highway=* & toll=mtb {set toll:bicycle=yes; delete toll}
highway=* & public_transport=platform {delete platform}
highway=track & tracktype ~ '(grade[1-5])' {set mkgmap:check=ok}
highway=track & tracktype=1 {set mkgmap:check=ok; set tracktype=grade1}
highway=track & tracktype=2 {set mkgmap:check=ok; set tracktype=grade2}
highway=track & tracktype=3 {set mkgmap:check=ok; set tracktype=grade3}
highway=track & tracktype=4 {set mkgmap:check=ok; set tracktype=grade4}
highway=track & tracktype=5 {set mkgmap:check=ok; set tracktype=grade5}
highway=track & tracktype=* & mkgmap:check!=ok {delete tracktype}

# access tags
bicycle ~ '(use_).*' { set bicycle=no; set motorcar=no; set access=no; delete cycleway; delete cycleway:left; delete cycleway:right }
bicycle:backward=use_sidepath {set bicycle:oneway=yes; set oneway=yes; delete bicycle:backward}
bicycle:forward=use_sidepath  {set bicycle:oneway=-1; set oneway=-1; delete bicycle:forward}
access=yes | access=permissive | access=official | access=unknown | access=designated {delete access}
access=no & (bicycle=yes | bicycle=designated | bicycle=official | bicycle=permissive) {delete access; add car=no }
access=destination {delete access}
bicycle=private {set bicycle=no; set motorcar=no}
vehicle=no | vehicle=private {add bicycle=no; add car=no}
car=private | car=permit {set car=no}
bicycle_road=yes & (car=no | car=destination | vehicle=destination | vehicle=no) {set highway=cycleway}
bicycle=dismount & highway!=footway & highway!=pedestrian {set bicycle=yes; add bicycle:dismount=yes}
bicycle=dismount & (highway=footway | highway=pedestrian) {delete bicycle; add bicycle:dismount=yes}
bicycle=yes {set motorcar=yes; set foot=yes} 
bicycle:conditional=* {add bicycle=yes; add motorcar=yes; add foot=yes} 
bicycle=destination | bicycle=official | bicycle=permissive {set motorcar=yes; set foot=yes; set bicycle=yes}
foot=designated {set foot=yes; add foot:designated=yes}
foot=destination | foot=official | foot=permissive {set foot=yes}
(highway=pedestrian | highway=footway) & oneway=* {delete oneway}
highway=* & highway ~ '(fiets|Fiets|mtb|Mtb|bike|Bike|rad|Rad|cycleway;|;cycleway)' {set highway=cycleway}
highway=* & highway ~ '.*(;).*' {set highway=unclassified}
highway=* & ice_road=yes {name '${name} (ice road)' | '(ice road)'} [0x10102 resolution 22]
highway=service & is_closed()=true &  (bicycle=no | access = no | access= private ) & foot!=yes {delete highway ; set area:highway=service} 

# set toll and ferry flags
highway=* & bicycle!=no {add toll=yes}
route=ferry {add mkgmap:ferry=1}
(ncn_from_relation=yes | rcn_from_relation=yes | icn_from_relation=yes | lcn_from_relation=yes | tcn_from_relation=yes) & state!=proposed
	{ add bicycleroute=yes; set toll=no; add bicycle = yes; add foot = yes } 
(ncn_from_relation=yes | rcn_from_relation=yes | icn_from_relation=yes | lcn_from_relation=yes | tcn_from_relation=yes) & state=proposed { name '${rref} (planned)' | '${nref} (planned)'} [0x10119 resolution 23 continue with_actions]
	
(access=no | access=private) & bicycle!=* & bicycleroute!=yes & cycleway!=* & mtb!=yes {set bicycle=no; set motorcar=no;}

aeroway=runway & is_closed()!=true [0x10117 resolution 20 continue with_actions]
aeroway=taxiway & is_closed()!=true [0x10117 resolution 23 continue with_actions]

(man_made=dyke | man_made=dike | embankment=dyke | embankment=yes | man_made=embankment) & railway!=* & highway!=* [0x10115 resolution 24 continue with_actions]
(man_made=dyke | man_made=dike | embankment=dyke | embankment=yes | man_made=embankment)  & (highway=* | railway=*) [0x10015 resolution 24 continue with_actions]
cutting=yes  [0x10215 resolution 24 continue with_actions]

# Roundabouts
junction=roundabout { add oneway=yes }
highway=cycleway & junction=roundabout { delete junction }
junction=roundabout [0x0c road_class=1 road_speed=1 resolution 24 continue with_actions]
junction=roundabout {set access=no}

# Convert highways to most specific
highway=raceway {set highway=service}
(highway=tertiary | highway=secondary) & (surface=unpaved | surface=gravel) {set highway=track; add tracktype=grade2}
(railway=abandoned | railway=disused) & highway!=* & (bicycle=yes | bicycle=designated) & !(state ~ '.*(proposed)') { add highway = cycleway }
highway=motorway_link | (highway=* & motorroad=yes) { set highway=motorway }
highway=trunk_link { set highway=trunk }
(highway=trunk | highway=motorway)  & bicycleroute=yes { set highway=primary }
(highway=trunk | highway=motorway)  & (cycleway:right=* | cycleway:left=* | cycleway=*) { set highway=motorway_bike }
(highway=trunk | highway=motorway)  & bicycle=yes { set highway=motorway_bike }

highway=trunk & mkgmap:country ~ '(NLD|BEL|LUX|FRA|DEU|AUT|CHE|DNK|HUN|ROU)' { set highway=motorway }
highway=trunk & bicycle=no { set highway=motorway }
highway=trunk { set highway=primary }
highway=primary_link { set highway=primary }
highway=secondary_link { set highway=secondary }
highway=tertiary_link { set highway=tertiary }
highway=byway | highway=minor | highway=living_street | highway=residential | highway=road { set highway=unclassified }
highway=bus_guideway  { set highway=service }
highway=service & (bicycle=yes | bicycle=designated | bicycleroute=yes) { set highway=unclassified }
#highway!=* & route!=ferry & railway!=* & waterway!=* & man_made!=* & bicycleroute=yes { add highway=unclassified }
#highway!=* & route!=ferry & railway!=* & waterway!=* & man_made!=* & mtb_from_relation=yes { add highway=track }
highway=unsurfaced { set highway=track }
highway=track & (tracktype=grade1 | surface ~ '(paved|asphalt|sett|concrete|concrete:plates|concrete:lanes|paving_stones)') { set highway=unclassified; delete tracktype; set mkgmap:check=ok }
highway=cycleroad  { set highway=cycleway }
cycleway=cyclestreet | bicycle_road=yes | (highway=unclassified & bicycle=designated) {add cyclestreet=yes} 
(cycleway=lane | cycleway=track) & highway=pedestrian {add bicycle=yes; add motorcar=yes; delete 'cycleway' }
cycleway=track & (highway=path | highway=footway | highway=bridleway) {add bicycle=yes; delete 'cycleway' }
cycleway=lane & (highway=track | highway=path | highway=footway | highway=bridleway) {add bicycle=yes; delete 'cycleway' }

highway=footway & bicycle=designated & !(mtb:scale ~ '[1-6]') { set highway=cycleway }
highway=path & bicycle=designated & foot:designated=yes { set highway=cycleway }
highway=path & bicycle=designated & surface ~ '(paved|asphalt|sett|concrete|concrete:plates|concrete:lanes|paving_stones)' { set highway=cycleway }
bicycle=designated { set bicycle=yes; add motorcar=yes }
highway=path & surface ~ '(paved|asphalt|sett|concrete|concrete:plates|concrete:lanes|paving_stones)' & access!=no & access!=private & vehicle!=no { set highway=pedestrian; add bicycle=yes; add motorcar=yes; }
highway=footway & surface ~ '(paved|asphalt|sett|concrete|concrete:plates|concrete:lanes|paving_stones)'  { set highway=pedestrian; add bicycle=no; add motorcar=no; }
highway=steps & area=yes { set highway=pedestrian; add bicycle=no; add motorcar=no; }
highway=path & foot=designated & bicycle!=yes { set highway=footway }
highway=path & horse=designated & (surface=sand | tracktype=grade4 | tracktype=grade5) & bicycle!=yes & foot!=yes  { set highway=bridleway; add mkgmap:unpaved=1; set motorcar=no; }
highway=track & horse=designated & (surface=sand | tracktype=grade4 | tracktype=grade5) & bicycle!=yes & foot!=yes  { set highway=bridleway; add mkgmap:unpaved=1; set motorcar=no; }
highway=bridleway & mkgmap:country=GBR & bicycle!=* {set highway=track; add mkgmap:unpaved=1; set motorcar=no;}
leisure=track & sport=cycling & area!=yes & is_closed()=false { add highway=service }
leisure=track & sport=bmx & area!=yes & is_closed()=false { add highway=path }
leisure=track & sport=mtb & area!=yes & is_closed()=false { add highway=path }
leisure=track & sport!=cycling & area!=yes & is_closed()=false { add highway=service; add access=no }

bicycle=lane { set cycleway=lane }
bicycleroute=yes & area=yes {set bicycleroute=no}

# Flag unpaved roads
highway=* & surface=metal_grid { delete surface }
highway=cycleway & surface ~ '(fine_gravel|compacted|shell|shells)' {set surface=paved; set mkgmap:unpaved=0; set motorcar=yes}
(surface=cobblestone | surface=unhewn_cobblestone) & (smoothness=intermediate | smoothness=good | smoothness=excellent | "cycleway:smoothness"=intermediate | "cycleway:smoothness"=good | "cycleway:smoothness"=very_good | "cycleway:smoothness"=excellent) {set surface=paved; set mkgmap:unpaved=0; set motorcar=yes}
(surface=cobblestone | surface=unhewn_cobblestone) & "cycleway:surface" ~ '(paved|asphalt|sett|concrete|concrete:plates|concrete:lanes|paving_stones)' {set surface=paved; set mkgmap:unpaved=0; set motorcar=yes}
highway=* &  bridge!=* & tracktype ~ '.*;.*' {delete tracktype}
highway=* &  bridge!=* & surface ~ '.*(ash|bad|clay|cob|compact|dirt|earth|erde|gr|loam|mud|peb|sand|soil|shotter|rock|turf|unpaved).*' { add mkgmap:unpaved=1; set motorcar=no }
highway=* &  bridge!=* & surface ~ '.*(cob|compact|gravel).*' { add unpaved=2 }
highway=* &  bridge!=* & smoothness ~ '.*(very_bad|horrible|impassable).*' { add mkgmap:unpaved=1; set motorcar=no }
highway=* &  bridge!=* & 
   (mtb:scale>0 | mtb:scale='0+' |
   tracktype ~ 'grade[2-6]' |
   sac_scale ~ '.*(mountain|alpine)_hiking' |
   sport=via_ferrata)
{ add mkgmap:unpaved=1; set motorcar=no; }

(highway=bridleway | highway=track | highway=unsurfaced | highway=footway)
& surface!=* & tracktype!=* & smoothness!=* & sac_scale!=* & bridge!=*
{ add mkgmap:unpaved=1; set motorcar=no }

highway=track & tracktype=grade2 & surface ~ '(fine_gravel|compacted|shell|shells)' & bicycle!=no { set mkgmap:unpaved=0; set motorcar=yes }
highway=path & surface ~ '(fine_gravel|compacted|shell|shells)' & bicycle=yes { set mkgmap:unpaved=0; set motorcar=no }
highway=* & bicycleroute=yes & surface ~ '(fine_gravel|compacted|shell|shells)' & bicycle!=no { set mkgmap:unpaved=0; set motorcar=yes }

highway=path
& surface!=* & tracktype!=* & smoothness!=* & sac_scale!=* & bridge!=* & length()>100
{ add mkgmap:unpaved=1; set motorcar=no }
(highway=unclassified | highway=service) & (mkgmap:unpaved=1) & service!=parking_aisle & !(cycleway=* | cycleway:right=* | cycleway:left=*) & mkgmap:check!=ok  { set highway=track; add tracktype=grade2; add motorcar=no; }
bicycle:dismount=yes & bridge!=* & man_made!=pier & public_transport!=platform { add mkgmap:unpaved=1 }


#oneway rules
(oneway=yes | oneway=-1) & (cycleway=opposite | cycleway=opposite_lane  | bicycle:oneway=no | oneway:bicycle=no | bicycle:backward=*) {set cycling=twoway; delete 'oneway'}
(oneway=1 | oneway=true) { set oneway=yes }
(oneway=no) { delete 'oneway' }
(oneway=yes & bicycle:backward=yes) {set cycling=twoway; delete 'oneway'}
(oneway=-1 | vehicle:forward=no) & bicycle:forward=yes {set cycling=twoway; delete 'oneway'}
(oneway:bicycle=yes | oneway:bicycle=1 | bicycle:oneway=1 | oneway:bicycle=true | bicycle:oneway=true | bicycle:oneway=1) {set bicycle:oneway=yes; set oneway=yes; delete 'oneway:bicycle'}
(oneway:bicycle=-1 | bicycle:oneway=-1) {set bicycle:oneway=-1; set oneway=-1; delete 'oneway:bicycle'}
(bicycle=opposite_lane | cycleway=opposite_track) { set cycleway=opposite_lane }
cycleway=share_busway {set cycleway=lane}
cycleway:left=share_busway {set cycleway:left=lane}
cycleway:right=share_busway {set cycleway:right=lane}
cycleway=opposite_share_busway { set cycleway=opposite_lane }
(cycleway=lane_left | cycleway:left=lane | cycleway=track_left | cycleway:left=path | cycleway:left=yes | cycleway:left=track ) { set cycleway=left }
(cycleway=right | cycleway=track_right | cycleway:right=path | cycleway:right=track | cycleway:right=yes | cycleway=lane_right | cycleway:right=lane) { set cycleway=right }
(cycleway=path | cycleway=yes | cycleway=both | cycleway=segregated | bicycle=track) { add bicycle=yes; delete 'cycleway' }
(cycleway=track | cycleway=left | cycleway=right) & highway=track { set highway=cycleway; add track=yes; set mkgmap:unpaved=0; delete 'cycleway'}
highway=cycleway & cycleway=* & cycleway!=opposite { delete 'cycleway' }
highway=cycleway & railway=* {delete 'railway'}
highway=cycleway & unpaved=2 {set mkgmap:unpaved=0}

# ways under construction
highway=construction [0x10019 resolution 22]

# Treat disused ways as highway=service, but at lower road_speed.
highway=* & disused=yes [0x07 road_class=0 road_speed=1 resolution 22 continue]


# bridges, tunnels, dams
waterway=dam & highway=* [0x2b default_name="dam" resolution 23 continue with_actions]
waterway=dam & highway!=* [0x08 default_name="dam" resolution 23 continue with_actions]
(highway=* | railway=*) & bridge=* & bridge!=no & bridge!=proposed & area!=yes [0x2b resolution 23 continue with_actions]
highway=* & (tunnel=yes | tunnel=true | tunnel=1 | covered=yes | tunnel=building_passage)  [0x09 road_class=3 road_speed=2 resolution 23]
waterway=* & (tunnel=yes | tunnel=culvert | culvert=yes | covered=yes) {delete 'waterway'}
#waterway=* & layer=-1 {delete 'waterway'}


#roads not allowed for cycling
highway=* & bicycle!=yes & (sac_scale ~ '.*alpine_hiking' | via_ferrata_scale>0) [0x10102 resolution 24]

highway=motorway [0x10000  resolution 18-19 continue with_actions]
highway=motorway [0x10014 resolution 20-21 continue with_actions]
highway=motorway {name '${ref|highway-symbol:box}'} [0x10013 resolution 22]

highway=* & access=private & bicycle!=yes & mkgmap:unpaved!=1 & area!=yes & highway!=footway & highway!=path & highway!=track [0x07 road_class=0 road_speed=0 resolution 22]


# render paved roads without motorcar traffic
highway=unclassified & (car=no|car=destination|car=private) & bicycle!=no & mkgmap:unpaved!=1 {add no_car=yes}
highway=unclassified & (access=no|access=private) &  bicycle=yes & mkgmap:unpaved!=1 {add no_car=yes}

# cycleways
(cyclestreet=yes | no_car=yes) & highway=unclassified [0x10116 resolution 23 continue with_actions]
cycleway=lane & oneway!=yes {add bicycle = yes; add foot = yes; add motorcar=yes } [0x26 resolution 23 continue with_actions]
(cycleway=track | cycleway=lane) & oneway=yes  [0x10005 resolution 23 continue with_actions]
cycleway=right [0x10005 resolution 23 continue with_actions]

cycleway=left | (cycleway=opposite_lane & oneway=yes) [0x10006 resolution 23 continue with_actions]
cycleway=opposite_lane & oneway=-1 [0x10006 resolution 23 continue with_actions]
cycleway=track & highway!=track & oneway!=yes [0x10009 resolution 23 continue with_actions]


# display direction arrows
highway=* & (oneway=yes | bicycle:oneway=yes ) & (cycling!=twoway) & bicycle!=no [0x10007 resolution 24 continue with_actions]
highway=* & cycleway=lane & cycling=twoway  [0x10011 resolution 24 continue with_actions]
highway=* & (cycleway=opposite_lane | cycleway=opposite | bicycle:oneway=no | oneway:bicycle=no) & cycling=twoway  [0x10008 resolution 24 continue with_actions]
highway=* & (oneway=-1 | bicycle:oneway=-1 ) & (cycling!=twoway) & bicycle!=no  [0x10007 resolution 24 continue with_actions]


# Display name / ref
highway=* & bicycleroute!=yes {name '${name} (${ref})' | '${name}' | '${ref}' }


mtb_from_relation=yes & bicycleroute!=yes {name '${mname}'} [0x1a resolution 22 continue with_actions]

# Ways sorted roughly by descending order of class
highway=cycleway & access!=no {add bicycle = yes; add foot = yes; set motorcar=yes }
highway=cycleway [0x11 resolution 20-22 continue with_actions]
highway=cycleway & (moped=yes | moped=designated) [0x10612 resolution 23 continue with_actions]
highway=cycleway & (moped=yes | moped=designated) & bicycle=no [0x10018 resolution 23]
highway=cycleway & (mofa=no | traffic_sign="NL:G13") {set toll=no} [0x10613 resolution 23 continue with_actions]
highway=cycleway & junction=roundabout [0x16 resolution 23]
highway=cycleway & track=yes {set motorcar=no} [0x1602 road_class=2 road_speed=2 resolution 23 continue with_actions]
highway=cycleway & mkgmap:unpaved=1 & unpaved!=2 {set motorcar=no} [0x0b road_class=1 road_speed=1 resolution 23 continue with_actions]
highway=cycleway & unpaved=2 [0x0e road_class=2 road_speed=2 resolution 23 continue with_actions]
highway=cycleway & mkgmap:unpaved!=1 & unpaved!=2 & track!=yes [0x16 road_class=3 road_speed=2 resolution 23 continue with_actions]

(highway=unclassified | highway=service) & service!=* [0x10000 resolution 20-21 continue with_actions]
(highway=unclassified | highway=service) & service!=* [0x10 resolution 22-22 continue with_actions]

highway=service & bicycle!=no [0x07 road_class=1 road_speed=2 resolution 23 continue]
highway=service & bicycle=no & foot!=no [0x07 road_class=0 road_speed=0 resolution 23 continue]
(highway=unclassified | highway=service) & bicycle!=no & junction=roundabout [0x060 resolution 23]
highway=unclassified & bicycle!=no [0x060 road_class=3 road_speed=2 resolution 23  continue with_actions]
(highway=unclassified | highway=service) & bicycle=no & car=no & foot!=no [0x08 road_class=0 road_speed=0 resolution 23]
highway=unclassified & bicycle=no [0x10018 resolution 23]
highway=service & bicycle=no & area!=yes [0x10018 resolution 23]

highway=tertiary [0x10001 resolution 20-22 continue with_actions]
highway=tertiary & bicycle!=no & junction=roundabout [0x050 resolution 23]
highway=tertiary & bicycle!=no [0x050 road_class=3 road_speed=2 resolution 23 continue with_actions]
highway=tertiary & bicycle=no {add foot=no} [0x10004 resolution 23]
 
highway=secondary [0x12 resolution 20-21 continue with_actions]
highway=secondary & bicycle!=no & junction=roundabout [0x040 resolution 22]
highway=secondary & bicycle!=no [0x040 road_class=2 road_speed=2 resolution 22 continue with_actions]
highway=secondary & bicycle=no  {add foot=no} [0x10003 resolution 22]

highway=primary [0x10000 resolution 18-19 continue with_actions]
highway=primary [0x10014 resolution 20-21 continue with_actions]
highway=primary & bicycle!=no & junction=roundabout [0x030 resolution 22]
highway=primary & bicycle!=no [0x030 road_class=1 road_speed=2 resolution 22 continue with_actions]
highway=primary & bicycle=no {add foot=no} [0x10002 resolution 22]

highway=motorway_bike  [0x10000  resolution 18-19 continue with_actions]
highway=motorway_bike  [0x10014 resolution 20-21 continue with_actions]
highway=motorway_bike  {name '${ref|highway-symbol:box}'} [0x01 road_class=1 road_speed=2 resolution 22]
 
highway=pedestrian [0x10000 resolution 22-22 continue with_actions]
highway=pedestrian & (access=private | access=no) & bicycle!=yes & bicycleroute!=yes & mtb_from_relation!=yes & mtb!=yes & foot!=yes [0x10101 resolution 23]
highway=pedestrian & (bicycle=yes | bicycleroute=yes | cycleway=*) & area!=yes {set motorcar=yes} [0x0816 road_class=3 road_speed=2 resolution 23 continue with_actions]
highway=pedestrian & (bicycle=yes | bicycleroute=yes | cycleway=*) & area=yes {set motorcar=yes} [0x08 road_class=2 road_speed=1 resolution 23 continue with_actions]
highway=pedestrian & bicycle!=yes & bicycleroute!=yes & cycleway!=* {set motorcar=no; add bicycle = no; add foot = yes; set mkgmap:unpaved=1} [0x08 road_class=0 road_speed=0 resolution 23 continue]

(highway=track | highway=path) & (access=private | access=no) & bicycle!=yes & bicycleroute!=yes & mtb_from_relation!=yes & foot=yes {set highway=footway}
(highway=track | highway=path) & (access=private | access=no) & bicycle!=yes & bicycleroute!=yes & mtb_from_relation!=yes & mtb!=yes & foot!=yes [0x10101 resolution 23]
(highway=track | highway=path | highway=footway) & bicycleroute=yes [0x1502 resolution 21-20 continue with_actions]
highway=track & bicycleroute!=yes [0x15 resolution 21-21 continue with_actions]
highway=track & (tracktype=grade1 | tracktype=grade2) [0x0f road_class=1 road_speed=1 resolution 22 continue]
highway=track & (tracktype=grade3 | tracktype=grade4 | tracktype=grade5 | tracktype!=*) & bicycleroute=yes {set motorcar=no} [0x0d road_class=1 road_speed=1 resolution 22 continue with_actions]
highway=track & tracktype=grade3 & (bicycle=yes | mtb_from_relation=yes) & bicycleroute!=yes {set motorcar=no} [0x0d road_class=1 road_speed=1 resolution 22]
highway=track & tracktype=grade3 & bicycleroute!=yes {set motorcar=no} [0x0f road_class=0 road_speed=0 resolution 22]
highway=track & (tracktype=grade4 | tracktype=grade5 | tracktype!=*) & bicycleroute!=yes & (bicycle=yes | mtb_from_relation=yes) {set motorcar=no} [0x0d road_class=0 road_speed=0 resolution 22]
highway=track & (tracktype=grade4 | tracktype=grade5 | tracktype!=*) & bicycleroute!=yes [0x15 resolution 22-22 continue]
highway=track & (tracktype=grade4 | tracktype=grade5 | tracktype!=*) & bicycleroute!=yes {set motorcar=no} [0x0a road_class=0 road_speed=0 resolution 23]

(highway=path | highway=footway | highway=bridleway) & bicycleroute=yes  [0x0d road_class=1 road_speed=1 resolution 22 continue with_actions]
(highway=path | highway=footway | highway=bridleway) & bicycleroute!=yes & (bicycle=yes  | mtb=yes | mtb_from_relation=yes | cycleway=*)  [0x0d road_class=1 road_speed=1 resolution 22]

(highway=path | highway=footway) & bicycleroute!=yes  [0x15 resolution 22-22 continue with_actions]
(highway=path | highway=footway) & bicycleroute!=yes {add access = no; add foot = yes; set mkgmap:unpaved=1} [0x0a road_class=0 road_speed=0 resolution 23]

highway=bridleway & bicycle!=yes & bicycleroute!=yes & mtb_from_relation!=yes & mtb!=yes {add access = no; add foot = yes; set mkgmap:unpaved=1} [0x2915 road_class=0 road_speed=0 resolution 23]

highway=steps  & (ramp:bicycle=yes | ramp=yes | ramp:wheelchair=yes) & (mkgmap:country=NLD | mkgmap:admin_level4="Vlaanderen") {add name="trap (met fietsgoot)"}
highway=steps  & (ramp:bicycle=yes | ramp=yes | ramp:wheelchair=yes) {add bicycle = yes; add motorcar=yes} [0x10005 default_name="steps (with ramp)" resolution 24 continue with_actions]
highway=steps & (bicycle=yes | bicycleroute=yes) {set mkgmap:unpaved=1;  set access=yes; add bicycle=yes; add foot=yes} [0x13 road_class=1 road_speed=0 resolution 24]
highway=steps {set mkgmap:unpaved=1; add access = no; add foot = yes; add oneway=yes} [0x13 road_class=0 road_speed=0 resolution 24]

# cycleroutes
bicycleroute=yes & bicycle!=no {set motorcar=yes}
highway=* & icn_from_relation=yes {name '${iref} (${iname|not-equal:iref})' | '${iref}' }  [0x00 resolution 15-15 continue]
highway=* & icn_from_relation=yes {name '${iref} (${iname|not-equal:iref})' | '${iref}' }  [0x24 resolution 16-17 continue]
highway=* & icn_from_relation=yes {name '${iref} (${iname|not-equal:iref})' | '${iref}' } [0x23 resolution 18-19 continue]
icn_from_relation=yes & railway!=rail {name '${iref|highway-symbol:hbox} (${iname|not-equal:iref})' | '${iref|highway-symbol:hbox}' } [0x02 resolution 20-21 continue] 

highway=* & ncn_from_relation=yes {name '${nref} (${nname|not-equal:nref})' | '${nref}' } [0x00 resolution 16-17 continue]
highway=* & ncn_from_relation=yes {name '${nref} (${nname|not-equal:nref})' | '${nref}' }[0x24 resolution 18-19 continue]
ncn_from_relation=yes & railway!=rail {name '${nref|highway-symbol:oval} (${nname|not-equal:nref})'| '${nref|highway-symbol:oval}'} [0x02 resolution 20-21 continue]
rcn_from_relation=yes & ncn_from_relation!=yes & icn_from_relation!=yes {name '${rnote}' | '${rref}' | '${rname}'}  [0x00 resolution 18-19 continue]
bicycleroute=yes & !(ncn_from_relation=yes | icn_from_relation=yes) [0x10119 resolution 20-21 continue]

(ncn_from_relation=yes | lcn_from_relation=yes | ncn_ref=* | rcn_ref=* | lcn_ref=*) {name '${nref|highway-symbol:oval}'| '${ncn_ref|highway-symbol:oval}' | '${rcn_ref|highway-symbol:oval}' | '${lcn_ref|highway-symbol:oval}' | '${lref|highway-symbol:oval}' }  [0x28 resolution 22 continue]
rcn_from_relation=yes {name '${rnote}' | '${rref}' | '${rname}'} [0x19 resolution 22 continue]
lcn_from_relation=yes {name '${lname}'} [0x27 resolution 22 continue]
bicycleroute=yes & junction!=roundabout & railway!=rail [0x02 road_class=3 road_speed=2 resolution 22 continue]

# Mop up any unrecognised highway types
highway=crossing  [0x10 road_class=1 road_speed=1 resolution 23]
#highway=* & area!=yes [0x06 road_class=0 road_speed=0 resolution 23]

railway=* & covered=yes {add tunnel=yes}
railway=* & (roller_coaster=track | sport=toboggan | attraction=rollercoaster | attraction=roller_coaster | railway=rollercoaster | railway=roller_coaster | service=rollercoaster | service=roller_coaster) [0x2a default_name="rollercoaster" resolution 22]
railway=abandoned & tunnel!=yes & highway!=* & (mkgmap:country=NLD | mkgmap:admin_level4="Vlaanderen") [0x15 default_name="voormalige spoorlijn" resolution 24]
railway=abandoned & tunnel!=yes & highway!=* & (mkgmap:country=DEU | mkgmap:country=AUT) [0x15 default_name="stillgelegten Eisenbahnstrecke" resolution 24]
railway=abandoned & tunnel!=yes & highway!=* & (mkgmap:country=FRA | mkgmap:admin_level4="Wallonie" | mkgmap:country=LUX) [0x15 default_name="voie ferree abandonnee" resolution 24]
railway=abandoned & tunnel!=yes & highway!=* [0x15 default_name="abandoned railway" resolution 23]
railway=disused | (railway=* & disused=yes) & tunnel!=yes [0x10112 resolution 23]
railway=rail & (service=* | usage=industrial | usage=tourism) & tunnel!=yes [0x10112 resolution 23]

railway=rail & tunnel=yes  [0x10113 resolution 20 continue with_actions]
railway=rail & tunnel!=yes & (trainroute=yes | highspeed=yes | usage=main) [0x2a resolution 18-19 continue with_actions]
railway=rail & tunnel!=yes & (trainroute=yes | highspeed=yes | usage=main) [0x14 resolution 20 continue]
railway=rail & tunnel!=yes & (trainroute=yes | highspeed=yes | usage=main) [0x10114 resolution 20]
railway=rail & tunnel!=yes & !(trainroute=yes | highspeed=yes | usage=main) [0x2a resolution 22-21 continue with_actions]
railway=rail & tunnel!=yes & !(trainroute=yes | highspeed=yes | usage=main) [0x14 resolution 23 continue]
railway=rail & tunnel!=yes & !(trainroute=yes | highspeed=yes | usage=main) [0x10114 resolution 23]

(railway=subway | railway=light_rail) & (layer>0) [0x10114 resolution 22]
(railway=subway | railway=light_rail) & (layer<0) [0x10113 resolution 22]
railway=subway [0x10113 resolution 22]
railway=light_rail [0x10114 resolution 22]

railway=construction & (mkgmap:country=NLD | mkgmap:admin_level4="Vlaanderen") [0x10113 default_name="in aanleg" resolution 22]
railway=construction [0x10113 default_name="construction" resolution 22]

railway=tram [0x2a default_name="tram" resolution 24]
(railway=preserved | railway=miniature) & (mkgmap:country=NLD | mkgmap:admin_level4="Vlaanderen") [0x2a default_name="historische spoorlijn" resolution 23]
railway=preserved | railway=miniature [0x2a default_name="preserved railway" resolution 23]

(railway=funicular | railway=narrow_gauge | railway=monorail) {name '${name}' | '${note}' | '${description}' | '${railway}' | '${aerialway}' } [0x2a resolution 22]
(aerialway=cable_car | aerialway=gondola |  aerialway=chair_lift | highway=elevator)  {name '${name}' | '${note}' | '${description}' | '${aerialway}' | '${highway}' } [0x2a resolution 24]

(public_transport=platform | highway=platform | railway=platform) & area!=yes {add access = no; add foot = yes} [0x08 road_class=0 road_speed=0 resolution 23]

route=ferry [0x10017  resolution 23-18 continue]
route=ferry & name ~ '(Waterbus)' [0x1b road_class=0 road_speed=0 resolution 24]
route=ferry & tourism=attraction & bicycleroute!=yes [0x10017  resolution 24]
route=ferry & seasonal=*  {set bicycle=no; set motorcar=no; add foot=yes; name '${name} seasonal (${seasonal})' } [0x1b road_class=0 road_speed=0 resolution 24 continue]
route=ferry & access:conditional=*  {set bicycle=no; set motorcar=no; add foot=yes; name '${name} access=${access:conditional}' } [0x1b road_class=0 road_speed=0 resolution 24 continue]
route=ferry & seasonal!=* [0x1b road_class=3 road_speed=0 resolution 24 continue]

bay=fjord { add waterway=river }
waterway=* & source=3dshapes { add natural=water }
(waterway=river | waterway=canal) & intermittent=yes [0x10A02 resolution 18]
waterway=river & natural!=water [0x18 resolution 18-19 continue]
waterway=river & natural!=water [0x1f resolution 20 continue]
waterway=canal & natural!=water [0x18 resolution 22-21 continue]
waterway=canal & natural!=water [0x1f resolution 23 continue]
waterway=stream & intermittent=yes [0x10A02 resolution 22]
waterway=stream & natural!=water & name=* [0x18 resolution 22-22 continue]
waterway=stream & natural!=water & name=* [0x1f resolution 23 continue]
waterway=stream & natural!=water & name!=* [0x18 resolution 24 continue]
waterway=drain & intermittent=yes [0x10A02 resolution 24]
waterway=drain & natural!=water [0x18 resolution 24 continue]
(waterway=ditch | barrier=ditch) & natural!=water [0x18 resolution 24]
waterway=weir & (mkgmap:country=NLD | mkgmap:admin_level4="Vlaanderen") [0x15 default_name="stuw" resolution 24]
waterway=weir [0x15 default_name="weir" resolution 24]

#other line elements
man_made=wildlife_crossing & natural!=* & landuse!=* & highway!=* & area!=yes [0x15 default_name="ecoduct" resolution 22]
#natural=coastline [0x25 resolution 18]
natural=cliff | geological=volcanic_caldera_rim [0x10115  resolution 23 continue]
barrier=city_wall | barrier=wall  [0x10012 resolution 23 continue]

#man_made=pier & area!=yes {name '${name}'} [0x08 default_name="pier" road_class=0 road_speed=0 resolution 24 continue with_actions]
man_made=pier & (area!=yes | is_closed()=true) [0x08 road_class=0 road_speed=0 resolution 24 continue with_actions]

# The boundary styles are after the highway rules because ways
# are frequently tagged with both and we want the highway to take priority.

boundary2=yes & member=yes & maritime!=yes & boundary_type!=territorial_waters & natural!=coastline { name '${boundary2_name}' }  [0x1001e resolution 14-20 continue]
boundary2=yes & member=yes & maritime!=yes & boundary_type!=territorial_waters & natural!=coastline { name '${boundary2_name}' } [0x1e resolution 21]
boundary4=yes & member=yes & maritime!=yes & boundary_type!=territorial_waters & natural!=coastline { name '${boundary4_name}' } [0x1d resolution 16]
boundary8=yes & member=yes & maritime!=yes & boundary_type!=territorial_waters & natural!=coastline { name '${boundary8_name}' } [0x1c resolution 24]


<finalize>
# The finalizer section is executed for each element when a rule with an element type matches
include 'inc/compat_lines'; 
